package web;

import domain.AllData;
import service.User_Service;
import service.impl.User_ServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.util.List;

@WebServlet("/userNodeDataServlet")
public class UserNodeDataServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //设置页面编码
        response.setContentType("text/html;charset=utf-8");
        request.setCharacterEncoding("utf-8");
        /*获取IMEI号*/
        HttpSession session = request.getSession();
        String IMEI= (String) session.getAttribute("IMEI");
        System.out.println("普通用户获取的"+IMEI);
        /*调用service查询节点信息*/
        User_Service user_service = new User_ServiceImpl();
        List<AllData> oneNodeData =  user_service.oneNodeData(IMEI);
        request.setAttribute("nodeData",oneNodeData);
        request.getRequestDispatcher("/userNodeData.jsp").forward(request,response);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doPost(request, response);
    }
}
